package com.leyou.item.web;

import com.leyou.common.dto.PageDTO;
import com.leyou.item.dto.SpuDTO;
import com.leyou.item.service.SpuService;
import com.leyou.item.service.SKuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("goods")
public class GoodsContoller {

    @Autowired
    private SpuService spuService;

/*    @Autowired
    private SKuService skuService;*/

    /*
    * 分页查询
    * */
    @GetMapping("spu/page")
    public ResponseEntity<PageDTO<SpuDTO>> pageQuery(
            @RequestParam(value = "page",defaultValue = "1")Integer page,
            @RequestParam(value = "rows",defaultValue = "5")Integer rows,
            @RequestParam(value = "saleable",required = false)Integer saleable
    ){

       return ResponseEntity.ok(spuService.pageQuery(page,rows,saleable));
    }


   /* *//*
    * 商品下架
    * *//*
    @GetMapping("saleable")
    public ResponseEntity<Void> modifySaleable(
            @RequestParam(value = "id",defaultValue = "1")Long id,
            @RequestParam(value = "saleable",defaultValue = "5")Boolean saleable
    ){

        spuService.editSaleable(id,saleable);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
*/

    /*
    * 新增商品
    *
    * 前端提交对象 RequestBody接收
    * */
  /*  @PostMapping("spu")
    public ResponseEntity<Void> addGoods(@RequestBody SpuDTO spuDTO ){

        spuService.addGoods(spuDTO);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }*/

  /*
  * 商品修改 ，数显，修改
    根据商品的id 查询该商品的详细信息
   */
    @PostMapping("{id}")
    public ResponseEntity<SpuDTO> queryGoodsBySpuID(@PathVariable("id") Long id ){
        SpuDTO spuDTO = spuService.queryGoodsBySpuID(id);
        return ResponseEntity.ok(spuDTO);
    }
}
